package converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;

import java.util.HashMap;

/**
 * 字符串类型转换成enum工厂
 */
public class StringToEnumConverterFactory implements ConverterFactory<String,StringBaseEnum> {
    private static final HashMap<Class,Converter> CONVERTERS=new HashMap<>();
    @Override
    public <T extends StringBaseEnum> Converter<String, T> getConverter(Class<T> targetType) {
        Converter converter = CONVERTERS.get(targetType);
        if (converter==null){
            converter=new StringToEnumConverter((targetType));
            CONVERTERS.put(targetType,converter);
        }
        return converter;
    }
}
